package com.ruoyi.survey.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.company.domain.XlkjCompanySurvey;
import com.ruoyi.company.service.IXlkjCompanyService;
import com.ruoyi.house.domain.XlkjHouseSurvey;
import com.ruoyi.house.service.IXlkjHouseService;
import com.ruoyi.ini.domain.XlkjIniSurvey;
import com.ruoyi.ini.service.IXlkjIniService;
import com.ruoyi.place.domain.XlkjPlaceSurvey;
import com.ruoyi.place.service.IXlkjPlaceService;
import com.ruoyi.population.domain.xlkjPopSurvey;
import com.ruoyi.population.service.IXlkjPopulationService;
import com.ruoyi.survey.domain.StatisticalData;
import com.ruoyi.survey.service.SurveyService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 辖区概况接口
 */

@RestController
@RequestMapping("/app/survey")
public class SurveyControllerApp extends BaseController {

    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private IXlkjPopulationService populationService;
    @Autowired
    private IXlkjHouseService houseService;
    @Autowired
    private IXlkjCompanyService companyService;
    @Autowired
    private IXlkjPlaceService placeService;
//    @Autowired
//    private IXlkjIncidentService incidentService;
    @Autowired
    private IXlkjIniService iniService;

    @Autowired
    private SurveyService surveyService;

    @GetMapping("/list")
    public AjaxResult list(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));

        StatisticalData statisticalData=new StatisticalData();
        statisticalData.setPeopleNum(populationService.selectPeopleNumByDeptId(deptId).getPopNum());
        statisticalData.setHouseNum(houseService.selectHouseNumByDeptId(deptId).getHouseNum());
        statisticalData.setCompanyNum(companyService.selectCompanyNumByDeptId(deptId).getCompanyNum());
        statisticalData.setPlaceNum(placeService.selectPlaceNumyDeptId(deptId).getPlaceNum());
        statisticalData.setIncidentsNum(iniService.selectIncidentsNumByDeptId(deptId).getIncidentNum());
        //辖区面积
        String measure = "";
        if(deptId == 101){
            measure = "1382";
        }else if(deptId == 200){
            measure = "643";
        }else if(deptId == 201){
            measure = "790";
        }else if(deptId == 202){
            measure = "782";
        }else if(deptId == 203){
            measure = "656";
        }else if(deptId == 102){
            measure = "772";
        }else if(deptId == 101){
            measure = "800";
        }
        statisticalData.setMeasure(measure);
        return AjaxResult.success(statisticalData);
    }

    @GetMapping("/population")
    public AjaxResult populationList(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));
        xlkjPopSurvey xlkjPopSurvey = populationService.selectPeopleNumByDeptId(deptId);
        return AjaxResult.success(xlkjPopSurvey);
    }

    @GetMapping("/house")
    public AjaxResult houseList(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));
        XlkjHouseSurvey xlkjHouseSurvey = houseService.selectHouseNumByDeptId(deptId);
        return AjaxResult.success(xlkjHouseSurvey);
    }

    @GetMapping("/company")
    public AjaxResult companyList(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));
        XlkjCompanySurvey xlkjCompanySurvey = companyService.selectCompanyNumByDeptId(deptId);
        return AjaxResult.success(xlkjCompanySurvey);
    }

    @GetMapping("/place")
    public AjaxResult placeList(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));
        XlkjPlaceSurvey xlkjPlaceSurvey = placeService.selectPlaceNumyDeptId(deptId);
        return AjaxResult.success(xlkjPlaceSurvey);
    }

    @GetMapping("/incident")
    public AjaxResult incidentList(){
        Long deptId = Long.valueOf(ServletUtils.getParameter("deptId", "103"));
        XlkjIniSurvey incidentSurvey = iniService.selectIncidentsNumByDeptId(deptId);
        return AjaxResult.success(incidentSurvey);
    }

}
